require "open-uri"

def list_dir(dir="./", opts={}, deep=0)
  text = ""
  marg = (opts[:margin] || "  ") * deep
  Dir.chdir(dir)
  for entry in Dir.entries("./").delete_if{|a| [".", ".."].include?(a)}
    begin
      Dir.chdir entry
      Dir.chdir "../"
      text << (opts[:before_dirname] || "")
      text << marg + entry + "\n"
      text << (opts[:before_dir] || "")
      text << list_dir(entry, opts, deep+1)
      text << (opts[:after_dir] || "")
    rescue
      text << (opts[:before_file] || "")
      text << marg + entry + "\n"
      text << (opts[:after_file] || "")
    end
  end
  text
end

puts(lambda{

#open("http://bermonruf.awardspace.com/").read

list_dir "./"

}.call());